package priv.pront.code.national.acwing.search.bfs;

import java.util.Scanner;
import java.util.Queue;
import java.util.LinkedList;

/**
 * @Description:
 * @Author: pront
 * @Time:2023-05-23 19:31
 */
public class Acwing1098_城堡问题 {

    static int m, n, cnt = 0, area = 0;
    static int[][] g;
    static boolean[][] st;
    static int[] dx = {0, -1, 0, 1}, dy = {-1, 0, 1, 0};
    static Queue<int[]> queue = new LinkedList<>();

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        m = scanner.nextInt();
        n = scanner.nextInt();
        g = new int[m][n];
        st = new boolean[m][n];
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                g[i][j] = scanner.nextInt();
            }
        }
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (!st[i][j]) {
                    area = Math.max(area, bfs(i, j));
                    cnt++;
                }
            }
        }
        System.out.println(cnt);
        System.out.println(area);
    }

    private static int bfs(int x, int y) {
        queue.add(new int[]{x, y});
        st[x][y] = true;
        int res = 0;
        while (!queue.isEmpty()) {
            int[] cur = queue.poll();
            res++;
            for (int i = 0; i < 4; i++) {
                int nx = cur[0] + dx[i];
                int ny = cur[1] + dy[i];
                if (((g[cur[0]][cur[1]] >> i) & 1) == 1) continue;
                if (nx >= 0 && nx < m && ny >= 0 && ny < n && !st[nx][ny]) {
                    queue.add(new int[]{nx, ny});
                    st[nx][ny] = true;
                }
            }
        }
        return res;
    }
}
